{% extends "layout.html" %}
{% set active_page = "notes" %}
{% set help_page = ["https://kizniche.github.io/Mycodo/Notes", _('Notes')] %}

{% block title %} - {{_('Edit Note')}}{% endblock %}

{% block body %}
<!-- Route: /note_edit -->
<div class="container">
  {% include 'flash_messages.html' %}

  <h4>{{_('Notes')}} <a href="{{help_page[0]}}" target="_blank"><span style="font-size: 16px" class="fas fa-question-circle"></span></a></h4>

  <div style="clear: both; padding: 1em 0;"></div>

  <h3>{{_('Edit Note')}}</h3>

  <p>Select one or more tag. {{_('Hold down the <kbd>Ctrl</kbd> or <kbd>&#8984;</kbd> key to select more than one')}}.</p>

  <form method="post" action="/note_edit/{{this_note.unique_id}}" enctype=multipart/form-data>
  {{form_note_mod.csrf_token}}
  {{form_note_mod.note_unique_id(value=this_note.unique_id)}}
  <div class="row">
    <div class="col-auto">
      {{form_note_mod.name.label(class_='control-label')}}
      <div>
        {{form_note_mod.name(class_='form-control', value=this_note.name)}}
      </div>
    </div>
    <div class="col-auto">
      {{form_note_mod.date_time.label(class_='control-label')}}
      <div>
        {{form_note_mod.date_time(class_='form-control', value=utc_to_local_time(this_note.date_time))}}
      </div>
    </div>
    <div class="col-auto">
      {{form_note_mod.files.label(class_='control-label')}}
      <div class="fileinput fileinput-new" data-provides="fileinput">
        <span class="btn btn-sm btn-file"><input id="files" name="files" type="file" multiple="" /></span>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-auto">
      {{form_note_mod.note_tags.label(class_='control-label')}}
      <div>
        <select class="form-control btn-sm" id="note_tags" name="note_tags" style="width: 100%;" size="{% if tags|length > 5 %}5{% else %}{{tags|length}}{% endif %}" multiple>
        {% if tags %}
          {% for each_tag in tags -%}
          <option value="{{each_tag.unique_id}}"{% if each_tag.unique_id in this_note.tags.split(',') %} selected{% endif %}>{{each_tag.name}}</option>
          {% endfor -%}
        {% else %}
          <option value="">{{dict_translation['none_available']['title']}}</option>
        {% endif %}
        </select>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-12">
      {{form_note_mod.note.label(class_='control-label')}}
      <div>
        {{form_note_mod.note(class_='form-control', rows='6')}}
      </div>
    </div>
  </div>
  <div class="row mt-3">
    <div class="col-auto">
      {{form_note_mod.note_cancel(class_='btn btn-primary')}}
    </div>
    <td>
      {{form_note_mod.note_del(class_='btn btn-primary', **{'onclick':'return confirm("Are you sure you want to delete this?")'})}}
    </td>
    <div class="col-auto">
      {{form_note_mod.note_save(class_='btn btn-primary')}}
    </div>
  </div>

  </form>

  <div style="clear: both; padding: 0.5em 0;"></div>

{% if this_note.files %}

   <div class="table-responsive">
    <table class="table">
      <tr>
        <td>Attached File</td>
        <td></td>
      </tr>

    {% for each_file in this_note.files.split(',') %}

    <form method="post" action="/note_edit/{{this_note.unique_id}}">
    {{form_note_mod.csrf_token}}
    {{form_note_mod.note_unique_id(value=this_note.unique_id)}}
    {{form_note_mod.file_selected(value=each_file)}}

      <tr>
        <td><pre><a href="/note_attachment/{{each_file}}">{{each_file[37:]}}</a></pre></td>
        <td>
          {{form_note_mod.rename_name(class_='form-control', value=each_file[37:])}}
        </td>
        <td>
          {{form_note_mod.file_rename(class_='btn btn-primary btn-block')}}
        </td>
        <td>
          {{form_note_mod.file_del(class_='btn btn-primary btn-block', **{'onclick':'return confirm("Are you sure you want to delete this?")'})}}
      </tr>

    </form>

    {% endfor -%}

    </table>
   </div>

  {% endif %}

  <div style="clear: both; padding: 0.5em 0;"></div>

</div>

{% endblock %}
